class Select
{
  int ms;
  int ws;
  Mod parent;
  int[] modSelected;
  int[][] wireSelected;
  Select(Mod tempParent){
    parent=tempParent;
    ms=0;
    ws=0;
    modSelected=new int[512];
    wireSelected=new int[512][3];
  }
  void doModSel(int tempIndex){
    parent.mods[modSelected[tempIndex]].selected=true;
  }
  void doWireSel(int tempIndex){
    parent.mods[wireSelected[tempIndex][0]].oPs[wireSelected[tempIndex][1]].wires[wireSelected[tempIndex][2]].selected=true;
    parent.mods[wireSelected[tempIndex][0]].oPs[wireSelected[tempIndex][1]].wires[wireSelected[tempIndex][2]].selIndex=ws;
    //println(ws);
  }
  void unModSel(int tempIndex){
    parent.mods[modSelected[tempIndex]].selected=false;
  }
  void unWireSel(int tempIndex){
    parent.mods[wireSelected[tempIndex][0]].oPs[wireSelected[tempIndex][1]].wires[wireSelected[tempIndex][2]].selected=false;
  }

  void doClearAll(){
    for(int i=0; i<ms; i++){
      unModSel(i);
    } 
    ms=0;
    for(int i=0; i<ws; i++){
      unWireSel(i);
    } 
    ws=0;
  }
  void setWireSel(int tempM, int tempP, int tempW){
    if(parent.mods[tempM-1].oPs[tempP-1].wires[tempW-1].selected){
      doClearAll();
    }
    else{
      doClearAll();
      ws=1;
      wireSelected[0][0]=tempM-1;
      wireSelected[0][1]=tempP-1;
      wireSelected[0][2]=tempW-1;
      doWireSel(0);
    }
  }
  void setModSel(int tempM){
      doClearAll();
      ms=1;
      modSelected[0]=tempM-1;
      //println(modSelected);
      doModSel(0);
 }
  void addModSel(int tempM){
    if(!parent.mods[tempM-1].selected){
      modSelected[ms]=tempM-1;
      doModSel(ms);
      ms++;
    }
    
  }
  void moveSel(float tempX, float tempY, int gm){
    
    for(int i=0;i<ms;i++){
      if(modSelected[i]!=gm){
        
        parent.mods[modSelected[i]].setB(parent.mods[modSelected[i]].bx-parent.mods[gm].bx+tempX,parent.mods[modSelected[i]].by-parent.mods[gm].by+tempY);
      }
    }
    parent.mods[gm].setB(tempX,tempY);


  }
  void addWireSel(int tempM, int tempP, int tempW){

    if(!parent.mods[tempM-1].oPs[tempP-1].wires[tempW-1].selected){

      wireSelected[ws][0]=tempM-1;
      wireSelected[ws][1]=tempP-1;
      wireSelected[ws][2]=tempW-1;

      doWireSel(ws);
      ws++;
    }
    else{
      printWS();
      parent.mods[tempM-1].oPs[tempP-1].wires[tempW-1].selected=false;
      //println(mods[tempM-1].oPs[tempP-1].wires[tempW-1].selIndex);
      int i=parent.mods[tempM-1].oPs[tempP-1].wires[tempW-1].selIndex;
      if(ws-1 > i){
        for(int del=i+1; del<ws;del++){
          //println(del);
          //mods[wires[del-1].getEndMod()].iPs[wires[del-1].getEndPort()].parent=mods[wires[del].getEndMod()].iPs[wires[del].getEndPort()].pare
          //t;
          parent.mods[tempM-1].oPs[tempP-1].wires[tempW-1].selIndex--;
          wireSelected[del-1]=wireSelected[del];
        }
      }

      ws--;
      printWS();

    }
  }

  void printWS(){
    for(int i=0; i<ws;i++){
      println(i+": M-"+wireSelected[i][0]+" P-"+wireSelected[i][1]+" W-"+wireSelected[i][2]);

    }
    println("------------------------------");
  }



  void deleteAll(){
    //put undo here
    for(int i=0;i<ws;i++){
      parent.mods[wireSelected[i][0]].oPs[wireSelected[i][1]].delWire(wireSelected[i][2]);
    }
    ws=0;
    for(int i=0;i<ms;i++){
      parent.mods[modSelected[i]].delMod();
    }

    
  }
  /*
        
   
   
   }
   void remSel(int tempM, int tempP, int tempW){
   mods[wires[tempIndex].getEndMod()].iPs[wires[tempIndex].getEndPort()].isUsed=false;
   if(ws-1 > tempIndex){
   for(int del=tempIndex+1; del<ws;del++){
   println(del);
   mods[wires[del-1].getEndMod()].iPs[wires[del-1].getEndPort()].parent=mods[wires[del].getEndMod()].iPs[wires[del].getEndPort()].parent;
   wires[del-1]=wires[del];
   }
   }
   ws--;
   }
   void allSel(){
   
   }
   void doClear(){
   
   }
   void doSel(tempI){
   
   }
   void doSelAll(){
   
   }
   */
}



